home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17041 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  46 lines

  1. Path: qualcomm.com!not-for-mail
  2. From: drew@qualcomm.com (Drew Eckhardt)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q]Virtualizing/Deriving
  5. Date: 13 Apr 1996 01:34:36 -0600
  6. Organization: QUALCOMM, Incorporated; San Diego, CA, USA
  7. Message-ID: <4knlec$lno@qualcomm.com>
  8. References: <40.91023.1613@channel1.com>
  9. NNTP-Posting-Host: littlebear.qualcomm.com
  10.  
  11. In article <40.91023.1613@channel1.com>,
  12. Dspse Bedford <dspse.bedford@channel1.com> wrote:
  13. >I just started using C++ so bare with me.
  14. >
  15. >Lets say I have a base class, BASE, with lots and lots of operators and 
  16. >member functions virtualized, like 10,000. Now I create 100 derived classes 
  17. >with BASE as their parent.  The first 99 derived classes use all of the 
  18. >operators and member function which exist in BASE, of course, if they need 
  19. >to redefine any they will.  The last derived class does not use some of the 
  20. >operators defined, lets say 2 out of 10,000. Now if I don't define these 2 
  21. >operators, the compiler will go pick up the parent definition if a user of 
  22. >the last derived class attempts to use any of these two operators.
  23. >  What can I do such that the compiler will give an error to the user?  I 
  24. >do not want to create another base class if possible.
  25.  
  26. You can declare the functions you don't want called as private, and fail 
  27. to define them.  Ie, given
  28.  
  29.    class foo : public base {
  30.    public:
  31.       // stuff
  32.  
  33.    private:
  34.       void dont_call ();
  35.    };
  36.  
  37. a user will get an error message if he attempts to call dont_call 
  38. (scope is resolved before overloading, so this will keep the user 
  39. from getting at a dont_call function with _any_ type signature in 
  40. the base class).
  41.  
  42. -- 
  43. <a href="http://www.poohsticks.org/drew/">Home Page</a>
  44. Four boxes : soap, ballot, jury, ammo.  | Work: drew@Qualcomm.COM       
  45. Use in that order.                      | Play: drew@PoohSticks.ORG    
  46.